package cn.lili.controller.promotion;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.BlindboxPrizeRecord;
import cn.lili.modules.promotion.entity.dos.BlindboxRuleOrder;
import cn.lili.modules.promotion.entity.vos.BlindboxPrizeRecordVO;
import cn.lili.modules.promotion.entity.vos.BlindboxRuleOrderVO;
import cn.lili.modules.promotion.entity.vos.BlindboxVO;
import cn.lili.modules.promotion.entity.vos.OrderStatusMhVO;
import cn.lili.modules.promotion.service.BlindboxPrizeRecordService;
import cn.lili.modules.promotion.service.BlindboxRuleOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;


/**
 * @author xiangqian
 */
@RestController
@Api(tags = "盲盒开奖记录接口")
@RequestMapping("/promotion/blindbox/prizerecord")
@RequiredArgsConstructor
public class BlindboxPrizeRecordController {

    private final BlindboxPrizeRecordService blindboxPrizeRecordService;
    private final BlindboxRuleOrderService blindboxRuleOrderService;

    @ApiOperation(value = "查询我的中将记录")
    @GetMapping("/getPrizerecordInfo/{goodsId}")
    public ResultMessage<BlindboxPrizeRecordVO> getPrizerecordInfo(@PathVariable String goodsId) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(blindboxPrizeRecordService.getPrizerecordInfo(currentUser, goodsId));
    }

    @ApiOperation(value = "查询往期开奖记录")
    @GetMapping("/getPrizerecordAll")
    public ResultMessage<List<BlindboxPrizeRecordVO>> getPrizerecordAll() {
        return ResultUtil.data(blindboxPrizeRecordService.getPrizerecordAll());
    }

    @ApiOperation(value = "新增开奖记录")
    @PostMapping("/save")
    public ResultMessage<Boolean> save(@RequestBody BlindboxPrizeRecord blindboxPrizeRecord){
        boolean flag = blindboxPrizeRecordService.save(blindboxPrizeRecord);
        return ResultUtil.data(flag);
    }

    @ApiOperation(value = "根据订单号查询盲盒订单商品")
    @GetMapping("/getBySn")
    public ResultMessage<List<BlindboxRuleOrderVO>> getBySn(String orderNo, String orderItemNo) {
        return ResultUtil.data(blindboxRuleOrderService.getBySn(orderNo,orderItemNo));
    }

    /**
     * 是否盲盒订单
     * 是否支付完成
     */
    @GetMapping("/getIsMh")
    public ResultMessage<OrderStatusMhVO> getIsMh(@RequestParam String orderNo) {
        return ResultUtil.data(blindboxRuleOrderService.getIsMh(orderNo));
    }
}
